package me.send.data.service.provider;

import java.util.Map;

import me.send.business.base.Pager;

public class CityProvider {
    
    public String list(Map<String, Object> param) {
    	String sql = "select * from opencity where 1=1 ";
    	if (param != null) {
    		String name = (String) param.get("name");
    		String letter = (String) param.get("letter");
    		Integer status = (Integer) param.get("status");
    		String start=(String) param.get("start");
    		String end=(String) param.get("end");
    		Pager page=(Pager) param.get("page");
    		if (name!=null&&!name.equals("")) {
    			sql += " and name like '%" + name +"%'";
    		}
    		if (letter!=null&&!letter.equals("")) {
    			sql += " and letter like '%" + letter +"%'";
    		}
    		if (status!=null&&status >= 0) {
    			sql += " and openstatus=" + status;
    		}
    		if(start!=null&&!start.equals("")){
    			sql+=" and createtime>='"+start+"'";
    		}
    		if(end!=null&&!end.equals("")){
    			sql+=" and createtime<'"+end+"'";
    		}
    		sql += " limit " + page.getStart() + "," + page.getRows();
    	}
    	return sql;
    }
    
    public String count(Map<String, Object> param) {
    	String sql = "select count(1) from opencity where 1=1 ";
    	if (param != null) {
    		String name = (String) param.get("name");
    		String letter = (String) param.get("letter");
    		Integer status = (Integer) param.get("status");
    		String start=(String) param.get("start");
    		String end=(String) param.get("end");
    		if (name!=null&&!name.equals("")) {
    			sql += " and name like '%" + name +"%'";
    		}
    		if (letter!=null&&!letter.equals("")) {
    			sql += " and letter like '%" + letter +"%'";
    		}
    		if (status!=null&&status >= 0) {
    			sql += " and openstatus=" + status;
    		}
    		if(start!=null&&!start.equals("")){
    			sql+=" and createtime>='"+start+"'";
    		}
    		if(end!=null&&!end.equals("")){
    			sql+=" and createtime<'"+end+"'";
    		}
    	}
    	return sql;
    }
    
    
}
